package com.example.webcomen.Handler;

import cn.hutool.json.JSONUtil;
import com.example.webcomen.Common.AjaxResult;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class SuccessHandler implements AuthenticationSuccessHandler {

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException {

        AjaxResult ajax = AjaxResult.success("登录成功");

        response.setContentType("application/json;charset=utf-8");

        response.getWriter().write(JSONUtil.toJsonStr(ajax));
    }
}
